package cn.bgs.serviceedu.service.impl;

import cn.bgs.serviceedu.entity.Collections;
import cn.bgs.serviceedu.dao.CollectionsMapper;
import cn.bgs.serviceedu.service.CollectionsService;
import cn.bgs.serviceutils.utils.CSException;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YiChen
 * @since 2021-11-04
 */
@Service
public class CollectionsServiceImpl extends ServiceImpl<CollectionsMapper, Collections> implements CollectionsService {

    @Autowired
    private CollectionsMapper collectionMapper;
    @Override
    public boolean selectId(Integer customerId, Integer doctorId) {

        Integer count = null;
        try {
            count = lambdaQuery()
                    .eq(Collections::getDoctorId, doctorId)
                    .eq(Collections::getCustomerId, customerId).count();
        } catch (Exception e) {
            throw new CSException(20001,"收藏列表查询错误");
        }

        if (count ==0){
            return false;
        }

        return true;
    }

    @Override
    public void removeCollection(Integer customerId, Integer doctorId) {
        collectionMapper.removeCollection(customerId,doctorId);
    }
}
